package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name = "order_payment_info")
public class OrderPaymentInfo extends BaseObject {
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("paymentMethod", paymentMethod)
				.append("status", status).append("paymentDate", paymentDate)
				.append("order", order).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof OrderPaymentInfo))
			return false;
		OrderPaymentInfo castOther = (OrderPaymentInfo) other;
		return new EqualsBuilder().append(id, castOther.id).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).toHashCode();
	}

	@OneToOne(optional = false, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "order_id", unique = true)
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(cascade = { CascadeType.MERGE })
	@JoinColumn(name = "payment_method_id")
	public PaymentMethod getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(PaymentMethod paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Column(name = "payment_date")
	public String getPaymentDate() {
		return paymentDate;
	}

	public void setPaymentDate(String paymentDate) {
		this.paymentDate = paymentDate;
	}

	private Long id;
	private PaymentMethod paymentMethod;
	private String status;
	private String paymentDate;
	private Order order;

}
